package com.slkj.shilixiaoyuanapp.ui.teacher.tool.notice;

import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.example.api.InjectParam;
import com.flyco.tablayout.SlidingTabLayout;
import com.slkj.shilixiaoyuanapp.R;
import com.slkj.shilixiaoyuanapp.base.ActivityInfo;
import com.slkj.shilixiaoyuanapp.base.BaseActivity;
import com.slkj.shilixiaoyuanapp.entity.FileEntity;
import com.slkj.shilixiaoyuanapp.entity.NoticeDetailEntity;
import com.slkj.shilixiaoyuanapp.net.HttpHeper;
import com.slkj.shilixiaoyuanapp.net.callback.CommonCallBack;
import com.slkj.shilixiaoyuanapp.view.dialog.LoadSuccessAndFailDialog;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindArray;
import butterknife.BindView;

@ActivityInfo(layout = R.layout.activity_notice_read_detail, title = "阅读名单",rightHint = "阅读提醒")
public class NoticeReadDetailActivity extends BaseActivity {
    @InjectParam
     ArrayList<NoticeDetailEntity.ReadEntity> read;
    @InjectParam
    int id;
    @InjectParam
    boolean isCanTx;
    @InjectParam
     ArrayList<NoticeDetailEntity.ReadEntity> noRead;
    @BindView(R.id.tab_layout)
    SlidingTabLayout tablayout;
    @BindView(R.id.viewpager)
    ViewPager viewpager;
    @BindArray(R.array.tool_notice_detail)
    String[] titles;
    private List<Fragment> fragments = new ArrayList<>();

    @Override
    protected void init() {
        NoticeReadDetailActivity__JumpCenter.bind(this);
        fragments.add(NoticeDetailReadFragment.get(read));
        fragments.add( NoticeDetailUnReadFragment.get(noRead));
        viewpager.setAdapter( new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragments.get(position);
            }

            @Override
            public int getCount() {
                return fragments.size();
            }

            @Nullable
            @Override
            public CharSequence getPageTitle(int position) {
                return titles[position];
            }
        });
        tablayout.setViewPager(viewpager);

    }

    @Override
    protected void onRightTitleClick() {
        if (isCanTx){
            HttpHeper.get().toolService().ydtx(id)
                    .compose(bindToLifecycle())
                    .compose(getThread())
                    .subscribe(new CommonCallBack<String>(true, NoticeReadDetailActivity.this) {
                        @Override
                        public void onCallBackSuccess(String data) {
                            LoadSuccessAndFailDialog.showSuccess(NoticeReadDetailActivity.this,data);
                            isCanTx = false;                                         }
                    });
        }else {
            LoadSuccessAndFailDialog.showFail(NoticeReadDetailActivity.this,"不能提醒");

        }
    }
}
